
<!--资讯审核-->
<template>
  <div class="AuditNewsPage">
    <div class="title">
      资讯审核
    </div>
    <!--详情窗口-->
    <el-dialog customClass="customWidth" fullscreen title="详情" :visible.sync="showCheckDialog">
      <el-form :model="showForm"  status-icon ref="showForm" label-width="100px" class="demo-ruleForm">
        <el-row>
          <el-col :span="18">
            <el-form-item label="标题">
              <el-input v-model="showForm.newTitle" disabled style="width: 120%" max="30" placeholder="请输入标题30字以内"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="18">
            <el-form-item label="发布时间 ">
              <el-input v-model="showForm.newTime" disabled style="width: 120%" max="30" placeholder="请输入标题30字以内"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="18">
            <el-form-item label="资讯状态" >
              <el-input v-model="showForm.newStatus" disabled style="width: 120%" max="30" placeholder="请输入标题30字以内"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="18">
            <el-form-item label="资讯封面">
              <img style="heith:100px;width:100px"
                   v-if="showForm.newImg"
                   class="el-upload-list__item-thumbnail"
                   :src="showForm.newImg" alt=""
              >
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="18">
            <el-form-item label="资讯内容" disabled >
              <el-input
                disabled
                style="width: 120%"
                type="textarea"
                :rows="8"
                max="200"
                placeholder="对现场信息的适当补充，如当日掌子面无进度，在施工中下台阶，仰拱等其他工程时，进行相应描述。"
                v-html="showForm.newContent">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="24" style="text-align: center;">
            <el-button v-if="this.showForm.newStatus=='待审核'" @click="auditNews('过审核')">通过审核</el-button>
            <el-button v-if="this.showForm.newStatus=='待审核'" @click="auditNews('未过审')">驳回</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>

    <!--头部区-->
    <div class="head">
      <el-form :inline="true" :model="form" >
        <el-form-item label="搜索资讯">
          <el-input v-model="form.search" placeholder="请输入"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="getData">查询</el-button>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="getRecent">近期发布</el-button>
        </el-form-item>

        <div>
          <el-form-item  label="发布时间">
            <el-date-picker
              v-model="form.data"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
        </div>

      </el-form>
    </div>


    <!--表格区-->
    <div class="content">
      <el-table
        :data="dataList"
        stripe
        style="width: 100%">
        <el-table-column
          type="index"
          width="50">
        </el-table-column>
        <el-table-column
          v-if="false"
          prop="id"
          width="50">
        </el-table-column>
        <el-table-column
          v-if="false"
          prop="userid"
          width="50">
        </el-table-column>
        <el-table-column
          v-if="false"
          prop="newImg"
          width="50">
        </el-table-column>
        <el-table-column
          v-if="false"
          prop="newContent"
          width="50">
        </el-table-column>
        <el-table-column
          prop="newTitle"
          label="资讯标题">
        </el-table-column>
        <el-table-column
          prop="newTime"
          label="创建时间">
        </el-table-column>
        <el-table-column
          width="100"
          prop="newStatus"
          label="资讯状态">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.newStatus == '过审核' ? 'success' : scope.row.newStatus == '待审核' ?'warning':'danger'"
              disable-transitions>{{scope.row.newStatus}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="showNew(scope.row)">查看</el-button>
            </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page.sync="pagination.currentPage"
          :page-size="pagination.pageSize"
          layout="total, prev, pager, next"
          :total="pagination.totals">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>

  import Common from '@/components/common/Common'
  const axios=require("axios");
    export default {
      name: "AuditNews",
      created:function(){
        if(sessionStorage.getItem("userid")==null&&sessionStorage.getItem("status")!='5'){
          this.$router.push("/login");
        }
      },
      mounted: function(){
        this.getData();
      },
      data(){
          return{
            pagination: {
              pageSize: 6, // 显示的条数
              totals: 12, // 总数
              currentPage: 1, // 当前第几页
            },
            dataList: [],
            showForm:{
              userid:'',
              newId:'',
              newTitle:'',
              newContent:'',
              newImg:'',
              newTime:'',
              newStatus:'',
            },
            form:{
              search:"",
              data:[new Date(2020, 10, 10, 10, 10), new Date(2021, 10, 11, 10, 10)],
              startTime:"",
              endTime:""
            },
            showCheckDialog:false,
          }
      },
      methods:{
        showNew(row){
          this.showForm.newContent=row.newContent;
          this.showForm.newId=row.id;
          this.showForm.newImg="http://localhost:8071"+row.newImg;
          this.showForm.newStatus=row.newStatus;
          this.showForm.newTime=row.newTime;
          this.showForm.newTitle=row.newTitle;
          this.showForm.userid=row.userid;
          this.showCheckDialog=true;
        },
        getRecent(){
          var vm=this;
          axios.post(Common.API+'news/getRecent',{
            newStatus:'待审核'
          })
            .then(function (res) {
              vm.pagination.currentPage=1;
              vm.pagination.totals=res.data.length;
              vm.dataList=res.data;
            })
            .catch(function (error) {
              console.log(error);
            });
        },
        getData(){
          var vm=this;
          axios.post(Common.API+'news/getNews?isAudit=1',{
            startTime:vm.form.data[0],
            endTime:vm.form.data[1],
            news:{
              newStatus:"待审核",
              newTitle:vm.form.search,
            },
            page:{
              current:vm.pagination.currentPage,
              size:vm.pagination.pageSize,
            }
          })
            .then(function (res) {
              vm.pagination.totals=res.data.total;
              vm.dataList=res.data.records;
            })
            .catch(function (error) {
              console.log(error);
            });
        },
        handleCurrentChange(val){
          this.pagination.currentPage=val;
          this.getData();
        },
        auditNews(val){

          var vm=this
          axios.post(Common.API+'news/auditNews',{
            news:{
              newStatus:val,
              id:vm.showForm.newId,
            },
            message:{
              userid:vm.showForm.userid,
              content:'标题为:'+vm.showForm.newTitle+' 的资讯通'+val,
              status:'未阅'
            },
          }).then(function (res) {
              if(res.data.code==200){
                vm.$message({
                  message: '审核通过',
                  type: 'success'
                });
                vm.showCheckDialog=false;
                vm.getData();
              }
            })
        }
      }
    }
</script>

<style scoped>
  body{
    height: 100%;
  }
  h1, h2 {
    font-weight: normal;
  }
  ul {
    list-style-type: none;
    padding: 0;
  }
  li {
    display: inline-block;
    margin: 0 10px;
  }
  a {
    color: #42b983;
  }
  .title{
    margin-left: 30px;
    line-height: 50px;
    width: 100%;
    font-size: 30px;
    height: 50px;
  }
  .AuditNewsPage{
    width: 100%;
    height:100px;
  }
  .AuditNewsPage .head{
    padding-top:20px;
    width: 80%;
    margin: 0 auto;
  }
  .AuditNewsPage .demo-form-block{
    display: block;
  }
  .AuditNewsPage .content{
    width: 80%;
    margin: 0 auto;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
